#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int a[N];
struct Node {
  int sum, mx, left, right;
} tr[N << 2];
#define sum(p) tr[p].sum
#define mx(p) tr[p].mx
#define left(p) tr[p].left
#define right(p) tr[p].right
Node merge(Node a, Node b) {
  Node res;
  res.sum = a.sum + b.sum;
  res.mx = max({a.mx, b.mx, a.right + b.left});
  res.left = max({a.left, a.sum + b.left});
  res.right = max({b.right, b.sum + a.right});
  return res;
}
void pushup(int p) { tr[p] = merge(tr[p << 1], tr[p << 1 | 1]); }
void build(int p, int l, int r) {
  if (l == r) {
    sum(p) = mx(p) = left(p) = right(p) = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  pushup(p);
}
void update(int x, int val, int p, int l, int r) {
  if (l == r) {
    sum(p) = mx(p) = left(p) = right(p) = val;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(x, val, p << 1, l, mid);
  else
    update(x, val, p << 1 | 1, mid + 1, r);
  pushup(p);
}
Node query(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) return tr[p];
  int mid = (l + r) >> 1;
  if (L <= mid && R > mid) {
    Node a = query(L, R, p << 1, l, mid);
    Node b = query(L, R, p << 1 | 1, mid + 1, r);
    return merge(a, b);
  } else if (L <= mid)
    return query(L, R, p << 1, l, mid);
  else
    return query(L, R, p << 1 | 1, mid + 1, r);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  build(1, 1, n);
  cin >> m;
  while (m--) {
    int op, x, y;
    cin >> op >> x >> y;
    if (op == 0)
      update(x, y, 1, 1, n);
    else
      cout << query(x, y, 1, 1, n).mx << endl;
  }
  return 0;
}